using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Microsoft.ConnectionEngine.SampleDeploymentManager.WizardPages
{
    public partial class SPRDatabaseConnectionPage : WizardPageBase
    {
        private const string SPR_DB_HOST = "sprDBHost";
        private const string SPR_DB_NAME = "sprDBName";
        private const string SPR_DB_USER = "sprDBUser";
        private const string SPR_DB_PASS = "sprDBPass";

        public SPRDatabaseConnectionPage()
        {
            InitializeComponent();
        }

        public override void Activate(ref Dictionary<string, object> parameters)
        {
            base.Activate(ref parameters);

            if (!_parameters.ContainsKey(SPR_DB_HOST)) _parameters.Add(SPR_DB_HOST, Utilities.GetCurrentHostName());
            if (!_parameters.ContainsKey(SPR_DB_NAME)) _parameters.Add(SPR_DB_NAME, "");
            if (!_parameters.ContainsKey(SPR_DB_USER)) _parameters.Add(SPR_DB_USER, "");
            if (!_parameters.ContainsKey(SPR_DB_PASS)) _parameters.Add(SPR_DB_PASS, "");

            if (_parameters.ContainsKey(SPR_DB_HOST)) txtDBHost.Text = _parameters[SPR_DB_HOST].ToString();
            if (_parameters.ContainsKey(SPR_DB_NAME)) txtDBName.Text = _parameters[SPR_DB_NAME].ToString();
            if (_parameters.ContainsKey(SPR_DB_USER)) txtDBUser.Text = _parameters[SPR_DB_USER].ToString();
            if (_parameters.ContainsKey(SPR_DB_PASS)) txtDBPass.Text = _parameters[SPR_DB_PASS].ToString();
        }

        private void txtDBHost_Leave(object sender, EventArgs e)
        {
            if (_parameters.ContainsKey(SPR_DB_HOST)) _parameters.Remove(SPR_DB_HOST);
            _parameters.Add(SPR_DB_HOST, txtDBHost.Text);
        }

        private void txtDBName_Leave(object sender, EventArgs e)
        {
            if (_parameters.ContainsKey(SPR_DB_NAME)) _parameters.Remove(SPR_DB_NAME);
            _parameters.Add(SPR_DB_NAME, txtDBName.Text);
        }

        private void txtDBUser_Leave(object sender, EventArgs e)
        {
            if (_parameters.ContainsKey(SPR_DB_USER)) _parameters.Remove(SPR_DB_USER);
            _parameters.Add(SPR_DB_USER, txtDBUser.Text);
        }

        private void txtDBPass_Leave(object sender, EventArgs e)
        {
            if (_parameters.ContainsKey(SPR_DB_PASS)) _parameters.Remove(SPR_DB_PASS);
            _parameters.Add(SPR_DB_PASS, txtDBPass.Text);
        }
    }
}
